#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int findLongestChain(vector<vector<int>>& pairs) {
        sort(pairs.begin(), pairs.end());
        int len = 1, end = pairs[0][1];
        for (int i = 1; i < pairs.size(); i++)
        {
            if (end < pairs[i][0]) len++, end = pairs[i][1];
            else if (end > pairs[i][1]) end = pairs[i][1];
        }
        return len;
    }
};